/*
 * @Author: Seon.Hu SeonHu@126.com
 * @Date: 2023-03-15 16:28:53
 * @LastEditors: Seon.Hu SeonHu@126.com
 * @LastEditTime: 2023-08-25 16:22:48
 * @FilePath: \bg-vben\src\components\AdList\src\hooks\useListContext.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import type { Ref } from 'vue';
import type { AdListProps, AdListActionType } from '../types/adList';
import { provide, inject, ComputedRef } from 'vue';

const key = Symbol('basic-table');

type Instance = AdListActionType & {
  wrapRef: Ref<Nullable<HTMLElement>>;
  getBindValues: ComputedRef<Recordable>;
};

type RetInstance = Omit<Instance, 'getBindValues'> & {
  getBindValues: ComputedRef<AdListProps>;
};

export function createListContext(instance: Instance) {
  provide(key, instance);
}

export function useListContext(): RetInstance {
  return inject(key) as RetInstance;
}
